tywx.SDKHandler = {
    _sceneHasOnLoad: !1,
    _userInfo: null,
    _checkData: null,
    ctor: function () {
        tywx.NotificationCenter.listen(tywx.EventType.SDK_LOGIN_SUCCESS, this.onSDKLoginSuccess, this),
            tywx.NotificationCenter.listen(tywx.EventType.SDK_LOGIN_FAIL, this.loginFail, this),
            tywx.NotificationCenter.listen(tywx.EventType.SCENE_ON_LOAD_COMPLETED, this._saveMyUserInfo, this),
            tywx.NotificationCenter.listen(tywx.EventType.WEIXIN_LOGIN_SUCCESS, this.onWXloginSuccess, this);
    },
    onWXloginSuccess: function (e) {
    },
    onSDKLoginSuccess: function (e) {
        console.log("onSDKLoginSuccess");
        this._checkData = e, Global.isLogined = !0;
        var t = tywx.SystemInfo.webSocketUrl;
        console.log("onSDKLoginSuccess success", "webSocketUrl:" + t), Global.config.host = t,
            tywx.Timer.setTimer(cc.director, this.timerCallbackUpdateScene, .1);
    },
    loginFail: function () {
        console.log("loginFail"), this._showLoginFailAlert();
    },
    setSceneHasOnLoad: function (e) {
        console.log("setSceneHasOnLoad onLoad:", e), this._sceneHasOnLoad = e;
    },
    timerCallbackUpdateScene: function () {
        tywx.SDKHandler._sceneHasOnLoad && (console.log("timerCallbackUpdateScene SCENE_ON_LOAD_COMPLETED"),
            tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventType_SCENE_ONLOAD, []),
            tywx.NotificationCenter.trigger(tywx.EventType.SCENE_ON_LOAD_COMPLETED), tywx.Timer.cancelTimer(cc.director, tywx.SDKHandler.timerCallbackUpdateScene));
    },
    _checkWxSetting: function (e) {
        var t = this;
        try {
            wx.getSetting({
                success: function (n) {
                    var o = n.authSetting;
                    if (!0 === o["scope.userInfo"]) {
                        console.error("用户已授权，直接服务器数据登录");
                        t._wxGetUserInfo(function (n) {
                            if (n) {
                                var o = {
                                    nickName: n.nickName,
                                    avatarUrl: n.avatarUrl
                                };
                                t._loginTuyooWithCode(e, o);
                            }
                        });
                    } else !1 === o["scope.userInfo"] ? (console.error("用户已拒绝授权"), t._loginTuyooWithCode(e)) : (console.error("未询问过用户授权"),
                        t._loginTuyooWithCode(e));
                },
                fail: function (n) {
                    console.error("wx.getSetting fail res:", n), t._loginTuyooWithCode(e);
                }
            });
        } catch (n) {
            console.error("checkWxSetting e:", n), t._loginTuyooWithCode(e);
        }
    },
    _wxGetUserInfo: function (e) {
        var t = this;
        console.log("_wxGetUserInfo "), t._userInfo ? (console.log("_wxGetUserInfo self._userInfo:" + t._userInfo),
        e && e(t._userInfo)) : wx.getUserInfo({
            success: function (n) {
                console.log("wx getUserInfo success, params:" + JSON.stringify(n));
                var o = n.userInfo;
                o.nickName, o.avatarUrl, o.gender;
                t._userInfo = o, e && e(o);
            },
            fail: function (t) {
                console.log("wx getUserInfo fail, res:" + JSON.stringify(t)), e && e();
            }
        });
    },
    _loginTuyooWithCode: function (e, t) {
        t || (t = {}), tywx.TuyooSDK.loginTuyooWithCode(e, t);
    },
    _saveMyUserInfo: function () {
        var e = this;
        authManager.checkAuthUserInfo(function (t) {
            console.log("_saveMyUserInfo");
            var n = e._checkData || {}, o = function (e) {
                e && (e.nickName && (tywx.UserInfo.userName = e.nickName), e.avatarUrl && (tywx.UserInfo.userPic = e.avatarUrl),
                    n.result ? (n.result.userName = tywx.UserInfo.userName, n.result.purl = tywx.UserInfo.userPic) : n.result = tywx.UserInfo,
                    console.log("_saveMyUserInfo data.result:", n.result), Global.notificationCenter.emit(Global.eventName.MSG_LOGIN_SUCCESS, n));
            };
            t ? e._wxGetUserInfo(o) : o(tywx.UserInfo);
        });
    },
    _showLoginFailAlert: function (e) {
        if (!Global.UIPopupManager.getPopupCompByUrl("PopupPanel/PopupAlert")) {
            var t = "";
            t = "登录失败，请重新登录", t = e = void 0 == e ? t : e;
            var n = Global.spriteAtlas.getOKSpf();
            Global.utils.showReconnectAlert(t, "确定", n, function () {
                console.error("----------重新登录--------- "), tywx.TuyooSDK.login();
            });
        }
    }
}, tywx.SDKHandler.ctor()
